.Dd $Mdocdate: February 23 2015 $
.Dt BN_SET_BIT 3
.Os
.Sh NAME
.Nm BN_set_bit ,
.Nm BN_clear_bit ,
.Nm BN_is_bit_set ,
.Nm BN_mask_bits ,
.Nm BN_lshift ,
.Nm BN_lshift1 ,
.Nm BN_rshift ,
.Nm BN_rshift1
.Nd bit operations on BIGNUMs
.Sh SYNOPSIS
.In openssl/bn.h
.Ft int
.Fo BN_set_bit
.Fa "BIGNUM *a"
.Fa "int n"
.Fc
.Ft int
.Fo BN_clear_bit
.Fa "BIGNUM *a"
.Fa "int n"
.Fc
.Ft int
.Fo BN_is_bit_set
.Fa "const BIGNUM *a"
.Fa "int n"
.Fc
.Ft int
.Fo BN_mask_bits
.Fa "BIGNUM *a"
.Fa "int n"
.Fc
.Ft int
.Fo BN_lshift
.Fa "BIGNUM *r"
.Fa "const BIGNUM *a"
.Fa "int n"
.Fc
.Ft int
.Fo BN_lshift1
.Fa "BIGNUM *r"
.Fa "BIGNUM *a"
.Fc
.Ft int
.Fo BN_rshift
.Fa "BIGNUM *r"
.Fa "BIGNUM *a"
.Fa "int n"
.Fc
.Ft int
.Fo BN_rshift1
.Fa "BIGNUM *r"
.Fa "BIGNUM *a"
.Fc
.Sh DESCRIPTION
.Fn BN_set_bit
sets bit
.Fa n
in
.Fa a
to 1
.Pq Li a|=(1<<n) .
The number is expanded if necessary.
.Pp
.Fn BN_clear_bit
sets bit
.Fa n
in
.Fa a
to 0
.Pq Li a&=~(1<<n) .
An error occurs if
.Fa a
is shorter than
.Fa n
bits.
.Pp
.Fn BN_is_bit_set
tests if bit
.Fa n
in
.Fa a
is set.
.Pp
.Fn BN_mask_bits
truncates
.Fa a
to an
.Fa n
bit number
.Pq Li a&=~((~0)>>n) .
An error occurs if
.Fa a
already is shorter than
.Fa n
bits.
.Pp
.Fn BN_lshift
shifts
.Fa a
left by
.Fa n
bits and places the result in
.Fa r
.Pq Li r=a*2^n .
.Fn BN_lshift1
shifts
.Fa a
left by one and places the result in
.Fa r
.Pq Li r=2*a .
.Pp
.Fn BN_rshift
shifts
.Fa a
right by
.Fa n
bits and places the result in
.Fa r
.Pq Li r=a/2^n .
.Fn BN_rshift1
shifts
.Fa a
right by one and places the result in
.Fa r
.Pq Li r=a/2 .
.Pp
For the shift functions,
.Fa r
and
.Fa a
may be the same variable.
.Sh RETURN VALUES
.Fn BN_is_bit_set
returns 1 if the bit is set, 0 otherwise.
.Pp
All other functions return 1 for success, 0 on error.
The error codes can be obtained by
.Xr ERR_get_error 3 .
.Sh SEE ALSO
.Xr bn 3 ,
.Xr BN_add 3 ,
.Xr BN_num_bytes 3
.Sh HISTORY
.Fn BN_set_bit ,
.Fn BN_clear_bit ,
.Fn BN_is_bit_set ,
.Fn BN_mask_bits ,
.Fn BN_lshift ,
.Fn BN_lshift1 ,
.Fn BN_rshift ,
and
.Fn BN_rshift1
are available in all versions of SSLeay and OpenSSL.
